﻿using System.ServiceProcess;
using SharpShare.Management;
using SharpShare.Configuration;
using System.Configuration;

namespace SharpShare.Service {
    public partial class Service : ServiceBase {
        private ShareManager _shareManager = new ShareManager();

        public Service() {
            InitializeComponent();
        }

        public System.Configuration.Configuration Configuration { get; set; }

        protected override void OnStart(string[] args) {
            if (this.Configuration == null) {
                this.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            }

            _shareManager.Configuration = this.Configuration;

            try {
                _shareManager.Start();
            } catch { }
        }

        protected override void OnStop() {
            if (_shareManager.State != ShareManagerState.Stopped) {
                _shareManager.Stop();
            }
        }

    }
}
